import optimizeCallback from './optimizeCallback'

/**
 * 运行一个函数多次，返回一个数组
 */
function times(n, iteratee, context) {
  n = Math.max(0, n)
  iteratee = optimizeCallback(iteratee, context, 1)
  let accu = Array(n)

  for (let i = 0; i < n; ++i) {
    accu[i] = iteratee(i)
  }

  return accu
}

export default times
